package com.shop.test;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import com.shop.entity.Emp;
import com.shop.util.MyBatisUtil;

public class MyBatisTest1 {
	
	@Test
	public void test4() throws IOException{
		SqlSession session = MyBatisUtil.getSqlSession();
		Map<String, Object> map = new HashMap<String,Object>();
		map.put("deptNo", 2);//部门为1的
		String statement = "com.shop.dao.EmpMapper"+".searchEmpByDept";
		session.selectOne(statement, map);
		Integer empCount  =(Integer) map.get("empCount");
		System.out.println("员工的人数:"+empCount);
		MyBatisUtil.closesSession(session);
	}
	
	@Test
	public void test1() throws IOException{
		SqlSession session = MyBatisUtil.getSqlSession();
		String statement = "com.shop.dao.EmpMapper"+".saveEmp";
		Emp emp = new Emp(null,"张无忌", new Date(), "教主",1234.56, 1);
		int result =  session.insert(statement, emp);
		System.out.println("获取的主键:"+emp.getId());
		System.out.println("受影响的行数:"+result);
		session.commit();
		MyBatisUtil.closesSession(session);
	}
	
}
